<template>
  <div style="z-index: 0">
    <el-row style="margin-bottom: 150px">
      <el-row>
        <el-col>
          <el-table
            @selection-change="toggleRowSelection"
            :data="tableData.result"
            style="width: 100%"
            ref="multipleTable"
          >
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column
              prop="baseInfo.idOfStr"
              label="订单号"
              width="80"
            ></el-table-column>
            <el-table-column label="产品" width="280">
              <template slot-scope="scope">
                <el-row>
                  <el-col :span="8">
                    <el-image
                      style="width: 40px; height: 40px"
                      :src="scope.row.productItems[0].productImgUrl[0]"
                      fit="fill"
                      :preview-src-list="
                        scope.row.productItems[0].productImgUrl
                      "
                    ></el-image>
                  </el-col>
                  <el-col class="show-line" :span="16"
                    >品名：{{ scope.row.productItems[0].name }}</el-col
                  >
                  <el-col class="show-line" :span="16"
                    >下单账户：{{ scope.row.baseInfo.buyerLoginId }}</el-col
                  >
                </el-row>
              </template>
            </el-table-column>
            <el-table-column label="店铺" width="180">
              <template slot-scope="scope">
                <span class="show-line"
                  >店铺：{{
                    scope.row.baseInfo.sellerContact.companyName
                  }}</span
                >
                <span>店主：{{ scope.row.baseInfo.sellerContact.name }}</span>
                <br />
                <span class="show-line"
                  >电话：{{ scope.row.baseInfo.sellerContact.mobile }}</span
                >
              </template>
            </el-table-column>
            <el-table-column label="规格" width="200">
              <template slot-scope="scope">
                <span
                  v-for="(item, index) in scope.row.productItems[0].skuInfos"
                  :key="index"
                  >{{ item.name }}:{{ item.value }}</span
                >
              </template>
            </el-table-column>
            <el-table-column label="价格" width="100">
              <template slot-scope="scope">
                <span>{{ scope.row.productItems[0].price }}</span>
              </template>
            </el-table-column>
            <el-table-column label="状态" width="100">
              <template slot-scope="scope">{{
                scope.row.productItems[0].statusStr
              }}</template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <i
                  @click="deleteGoods(scope.row.baseInfo.idOfStr)"
                  class="el-icon-delete"
                ></i>
                <el-button
                  @click="
                    $router.push({
                      path: `/1688/logistics/${scope.row.baseInfo.idOfStr}`,
                    })
                  "
                  >物流</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
      <el-row>
        <el-pagination
          background
          layout="prev, pager, next"
          :page-size="20"
          :total="total"
          @current-change="splitPage"
        ></el-pagination>
      </el-row>
    </el-row>
    <order :form="form" style="width: 82%; background: white" />
  </div>
</template>

<script>
import order from "@/components/Order";
export default {
  name: "orderDetail",
  data() {
    return {
      total: 0,
      tableData: {},
      multipleTable: [],
      form: {
        amount: 0,
        total: 0,
        orderId: [],
      },
    };
  },
  methods: {
    splitPage(res) {
      this.getOrderDetails(res);
    },
    deleteGoods(id) {
      this.$alert("确定删除吗？", "提醒", {
        confirmButtonText: "确定",
        callback: (action) => {
          if (action == "cancel") {
            console.log(action);
          } else {
            this.$http
              .delete(
                `/ali-order/1688/cancel-order/${id}`
              )
              .then((res) => {
                let result = JSON.parse(res.data.message);
                if (result.success) {
                  this.$message({ message: "删除成功", type: "success" });
                  this.getOrderDetails();
                } else {
                  this.$message({
                    message: "" + result.errorMessage,
                    type: "warning",
                  });
                }
              })
              .catch((err) => {});
          }
        },
      });
    },
    async getOrderDetails(current = 1) {
      await this.$http
        .post(`/ttOrder/get-ali-order/${current}`)
        .then((response) => {
          if (response.data.code == 403) {
            this.$message({
              message: "网络错误【" + response.data.message + "】",
              type: "warning",
            });
          } else {
            this.tableData = JSON.parse(response.data.message);
            this.total = this.tableData.totalRecord;
          }
        })
        .catch((err) => {
          this.$message({ message: "网络错误", type: "warning" });
        });
    },
    toggleRowSelection(res) {
      this.form.amount = 0;
      this.form.total = 0;
      this.form.orderId = [];
      res.forEach((item) => {
        this.form.amount +=
          item.productItems[0].price * item.productItems[0].quantity;
        this.form.total = res.length;
        this.form.orderId.push(item.baseInfo.idOfStr);
      });
    },
  },
  components: {
    order,
  },
  created() {
    this.getOrderDetails();
  },
};
</script>

<style scoped>
.show-line {
  display: inline-block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
